package com.lishe.lishe.lishe.module.mall.adapter;


import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.lishe.base.common.adapter.CommonAdapter;
import com.lishe.base.common.adapter.base.ItemViewDelegate;
import com.lishe.base.common.adapter.base.ViewHolder;
import com.lishe.base.view.FullGridLayoutManager;
import com.lishe.base.viewpager.MZBannerView;
import com.lishe.base.viewpager.MZViewHolder;
import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.mall.bean.DataItemBean;
import com.lishe.lishe.lishe.module.mall.bean.GoodsItemsBean;
import com.lishe.lishe.lishe.module.mall.bean.HomeResponse;
import com.lishe.lishe.lishe.module.mall.presenter.IndexPresenter;
import com.lishe.lishe.lishe.module.mall.presenter.MallMainAdapterPresenter;
import com.lishe.lishe.lishe.utils.FullyLinearLayoutManager;

/**
 * 标    题：
 * 功能描述：
 * 作    者：zouxx
 * 创建时间：2018/8/14
 */

public class MainMenuItemViewDelegate implements ItemViewDelegate<DataItemBean> {

    private Activity activity;

    public MainMenuItemViewDelegate(Activity activity) {
        this.activity = activity;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_index_recyclerview;
    }

    @Override
    public boolean isForViewType(DataItemBean item, int position) {
        return item.style == 3;
    }

    @Override
    public void convert(ViewHolder holder, DataItemBean dataBean, int position) {
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        holder.itemView.setLayoutParams(params);
        RecyclerView recyclerView = holder.getView(R.id.item_recyclerView);
        holder.setVisible(R.id.rl_title, false);
        recyclerView.setLayoutManager(new FullyLinearLayoutManager(activity){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        recyclerView.setAdapter(new CommonAdapter<GoodsItemsBean>(activity, R.layout.item_mall_go_image, dataBean.list) {

            @Override
            protected void convert(ViewHolder holder, GoodsItemsBean listBean, int position) {
                ImageLoaderUtils.displayImage(activity, listBean.imgUrl, holder.getView(R.id.image),R.drawable.mall_go_icon);
                holder.setOnClickListener(R.id.image, v -> IndexPresenter.setOnClick(activity, listBean));
            }
        });
    }
}
